package cn.mesmile.design.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zb
 * @version 1.0
 * @date 2020/11/21 14:26
 * @description
 */
public class Subject {

    private List<Observer> observerList = new ArrayList<>();

    /**
     * 新增观察者
     * @param observer
     */
    public void addObserver(Observer observer) {
        this.observerList.add(observer);
    }

    /**
     * 删除观察者
     * @param observer
     */
    public void deleteObserver(Observer observer){
        this.observerList.remove(observer);
    }

    public void notifyAllObserver() {
        for (Observer observer : observerList) {
            observer.update();
        }
    }


}
